﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

public partial class control_tintuc_wuc_tintucdulich : System.Web.UI.UserControl
{
    public string TinTucDuLich = ConfigurationSettings.AppSettings["TinTucDuLich"].Replace("+", "&");

    public string HtmlWriteTinTucDuLich(string link_web)
    {
        string htmlCode = "";
        string htmlCodeList = "<ul class='ul_list_tintucdulich'>";
        DataTable dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(5) * FROM dev_news WHERE link_web = '" + link_web + "' AND status = 1 ORDER BY idnews DESC");
        int tCount = dtTour.Rows.Count;
        if (tCount > 0)
        {
            int dem = 0;
            htmlCode += "<div class=\"div_titlebar\"><a href='/tintuc.aspx" + dtTour.Rows[0]["link_web"] + "' title='Tin tức du lịch'><p class=\"p_tilebar_all\">Tin tức du lịch</p></div>";
            foreach (DataRow item in dtTour.Rows)
            {
                if (dem == 0)
                {
                    string strTitleAlt = item["title"].ToString();
                    string strUrl = "/chitiettin.aspx?idnews=" + item["idnews"];
                    string strTitle = item["title"].ToString().Length < 120 ? item["title"].ToString() : item["title"].ToString().Substring(0, 120);
                    string strDes = item["sapo"].ToString().Length < 150 ? item["sapo"].ToString() : item["sapo"].ToString().Substring(0, 150);

                    htmlCode += "<div class='div_newsnewest'>";
                    htmlCode += "<a href='" + strUrl + "' title='" + strTitleAlt
                             + "'><img alt='" + strTitleAlt + "' class='img_news_pic' src='/files_upload/images/news/" + item["picture"] + "' /></a>";
                    htmlCode += "<a class='a_title_news' href='" + strUrl + "' title='" + strTitleAlt + "'>" + strTitle + "</a><br />";
                    htmlCode += "<a class='a_title_news a_descriptions' title='" + strTitleAlt + "'>" + strDes + "</a>";
                    htmlCode += "</div>";
                    dem++;
                }
                else
                {
                    string strTitle = item["title"].ToString().Length < 100 ? item["title"].ToString() : item["title"].ToString().Substring(0, 100);
                    htmlCodeList += "<li><a href='/chitiettin.aspx?idnews=" + item["idnews"] + "'><img alt='" + item["title"]
                                 + "' class='' src='/files_upload/images/news/" + item["picture"] + "' />" + strTitle + "</a></li>";
                }
            }
            htmlCodeList += "</ul>";
        }

        return htmlCode + htmlCodeList;
    }
}